```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>最大子数组和 | 算法可视化</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
        }
        .code-block {
            background-color: #1e293b;
            color: #f8fafc;
            border-radius: 0.5rem;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .text-gradient {
            background-clip: text;
            -webkit-background-clip: text;
            color: transparent;
            background-image: linear-gradient(135deg, #6366f1, #8b5cf6);
        }
        .first-letter {
            font-size: 3.5rem;
            line-height: 1;
            float: left;
            margin-right: 0.5rem;
            margin-top: 0.3rem;
            font-weight: 700;
            color: #6366f1;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto">
            <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">最大子数组和问题</h1>
            <p class="text-xl md:text-2xl font-light mb-8 opacity-90">动态规划与贪心算法的完美应用</p>
            <div class="flex items-center space-x-4">
                <div class="flex items-center">
                    <i class="fas fa-clock text-xl mr-2"></i>
                    <span>时间复杂度: O(n)</span>
                </div>
                <div class="flex items-center">
                    <i class="fas fa-memory text-xl mr-2"></i>
                    <span>空间复杂度: O(1)</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-question-circle text-indigo-500 mr-3"></i>
                <span>问题描述</span>
            </h2>
            <div class="bg-white rounded-xl shadow-md p-6">
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="first-letter">给</span>定一个整数数组 <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">nums</code>，找到一个具有最大和的连续子数组（子数组最少包含一个元素），返回其最大和。
                </p>
                <div class="mt-6 p-4 bg-indigo-50 rounded-lg border-l-4 border-indigo-500">
                    <p class="font-medium text-indigo-800 mb-2">示例:</p>
                    <p class="text-gray-700">输入: <code class="bg-gray-200 px-2 py-1 rounded">[-2,1,-3,4,-1,2,1,-5,4]</code></p>
                    <p class="text-gray-700">输出: <code class="bg-gray-200 px-2 py-1 rounded">6</code></p>
                    <p class="text-gray-700">解释: 连续子数组 <code class="bg-gray-200 px-2 py-1 rounded">[4,-1,2,1]</code> 的和最大，为6。</p>
                </div>
            </div>
        </section>

        <!-- Core Algorithms -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-brain text-indigo-500 mr-3"></i>
                <span>核心算法</span>
            </h2>
            <div class="grid md:grid-cols-2 gap-8">
                <!-- Dynamic Programming -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="bg-indigo-600 px-6 py-4">
                        <h3 class="text-xl font-bold text-white flex items-center">
                            <i class="fas fa-project-diagram mr-3"></i>
                            动态规划法
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <p class="text-gray-700 mb-2"><strong>定义:</strong></p>
                            <p>定义 <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">dp[i]</code> 为以 <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">nums[i]</code> 结尾的最大子数组和</p>
                            <p class="mt-2">递推公式: <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">dp[i] = max(dp[i-1] + nums[i], nums[i])</code></p>
                        </div>
                        <div class="mb-4">
                            <p class="text-gray-700 mb-2"><strong>复杂度分析:</strong></p>
                            <div class="flex space-x-4">
                                <span class="flex items-center"><i class="fas fa-clock text-indigo-500 mr-1"></i> 时间: O(n)</span>
                                <span class="flex items-center"><i class="fas fa-memory text-indigo-500 mr-1"></i> 空间: O(1)</span>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Greedy Algorithm -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all duration-300 card-hover">
                    <div class="bg-purple-600 px-6 py-4">
                        <h3 class="text-xl font-bold text-white flex items-center">
                            <i class="fas fa-chart-line mr-3"></i>
                            贪心算法
                        </h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <p class="text-gray-700 mb-2"><strong>核心思想:</strong></p>
                            <p>维护当前最大和 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">max_sum</code> 和当前和 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">curr_sum</code></p>
                            <p class="mt-2">当 <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded">curr_sum < 0</code> 时重置为 0</p>
                        </div>
                        <div class="mb-4">
                            <p class="text-gray-700 mb-2"><strong>复杂度分析:</strong></p>
                            <div class="flex space-x-4">
                                <span class="flex items-center"><i class="fas fa-clock text-purple-500 mr-1"></i> 时间: O(n)</span>
                                <span class="flex items-center"><i class="fas fa-memory text-purple-500 mr-1"></i> 空间: O(1)</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-chart-pie text-indigo-500 mr-3"></i>
                <span>算法可视化</span>
            </h2>
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="mermaid">
                    graph TD
                    A[最大子数组和问题] --> B[动态规划法]
                    A --> C[贪心算法]
                    B --> D[定义dp[i]为以nums[i]结尾的最大和]
                    B --> E[状态转移方程: dp[i]=max(dp[i-1]+nums[i], nums[i])]
                    C --> F[维护当前和curr_sum]
                    C --> G[当curr_sum<0时重置为0]
                    C --> H[记录全局最大值max_sum]
                </div>
            </div>
        </section>

        <!-- Sample Code -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-code text-indigo-500 mr-3"></i>
                <span>示例代码</span>
            </h2>
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="bg-gray-800 px-6 py-3 flex items-center justify-between">
                    <div class="flex items-center">
                        <div class="h-3 w-3 bg-red-500 rounded-full mr-2"></div>
                        <div class="h-3 w-3 bg-yellow-500 rounded-full mr-2"></div>
                        <div class="h-3 w-3 bg-green-500 rounded-full"></div>
                    </div>
                    <div class="text-gray-300 text-sm">Java - 动态规划实现</div>
                </div>
                <div class="p-6 code-block">
                    <pre class="text-gray-100 overflow-x-auto">
<code>public int maxSubArray(int[] nums) {
    // 处理边界情况
    if (nums == null || nums.length == 0) {
        return 0;
    }
    
    // currSum表示以当前元素结尾的最大子数组和
    int currSum = nums[0];
    // maxSum记录全局最大子数组和
    int maxSum = nums[0];
    
    // 从第二个元素开始遍历
    for (int i = 1; i < nums.length; i++) {
        // 对于当前元素，要么加入前面的子数组，要么重新开始一个子数组
        currSum = Math.max(nums[i], currSum + nums[i]);
        // 更新全局最大子数组和
        maxSum = Math.max(maxSum, currSum);
    }
    
    // 返回最大子数组和
    return maxSum;
}</code>
                    </pre>
                </div>
            </div>
        </section>

        <!-- Key Insights -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-lightbulb text-indigo-500 mr-3"></i>
                <span>关键洞察</span>
            </h2>
            <div class="bg-white rounded-xl shadow-md p-8">
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <div class="flex items-start mb-6">
                            <div class="bg-indigo-100 p-3 rounded-full mr-4">
                                <i class="fas fa-arrow-circle-right text-indigo-600 text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-2">动态规划思想</h4>
                                <p class="text-gray-700">将问题分解为子问题，记录每个位置结束的最大和，避免重复计算。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-purple-100 p-3 rounded-full mr-4">
                                <i class="fas fa-fire text-purple-600 text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-2">贪心选择</h4>
                                <p class="text-gray-700">当当前和为负时，舍弃前面的子数组，因为负和对后续求和没有贡献。</p>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div class="flex items-start mb-6">
                            <div class="bg-blue-100 p-3 rounded-full mr-4">
                                <i class="fas fa-chart-bar text-blue-600 text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-2">空间优化</h4>
                                <p class="text-gray-700">只需存储前一个状态的结果，可将空间复杂度优化到 O(1)。</p>
                            </div>
                        </div>
                        <div class="flex items-start">
                            <div class="bg-green-100 p-3 rounded-full mr-4">
                                <i class="fas fa-project-diagram text-green-600 text-xl"></i>
                            </div>
                            <div>
                                <h4 class="text-xl font-semibold mb-2">Kadane算法</h4>
                                <p class="text-gray-700">该问题的最优解通常被称为Kadane算法，是动态规划的特例。</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Application Scenarios -->
        <section>
            <h2 class="text-3xl font-bold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-rocket text-indigo-500 mr-3"></i>
                <span>应用场景</span>
            </h2>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-md p-6 transition-all duration-300 hover:shadow-lg card-hover">
                    <div class="text-indigo-600 text-4xl mb-4">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">股票交易</h3>
                    <p class="text-gray-700">计算一段时间内股票价格的最大收益，类似于寻找最大子数组和。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 transition-all duration-300 hover:shadow-lg card-hover">
                    <div class="text-purple-600 text-4xl mb-4">
                        <i class="fas fa-image"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">图像处理</h3>
                    <p class="text-gray-700">在图像分析中寻找亮度变化最大的区域，用于边缘检测。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 transition-all duration-300 hover:shadow-lg card-hover">
                    <div class="text-blue-600 text-4xl mb-4">
                        <i class="fas fa-soundcloud"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">信号处理</h3>
                    <p class="text-gray-700">寻找信号序列中能量最大的连续片段，用于语音识别等应用。</p>
                </div>
            </div>
        </section>
    </main>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```